'use strict'

define(['jquery', 'bootstrap', 'datetimepicker', 'datetimepickerCN', 'select2', 'validate', 'validate.en', 'shiftform',], function($) {
  
  return {
        
    init: function(data) {
        this.initPage(data.complete);
        this.initExport();
    },
    
    initPage: function(complete){
        $('select[name="siteId"]').select2({
            minimumResultsForSearch : -1,
            allowClear : false,
            width: '150'
        });

        $('select[name="siteId"]').change(function(){ 

            var siteId = $(this).children('option:selected').val();
            window.location.href = window.__CTX__.root + "/satisfaction-surveys?siteId=" + siteId + "&complete=" + (complete ? complete : "");

        })
    },
    
    initExport: function(){
        $(document).on('shown.bs.modal', ' #export', function(e){
            
            $(e.currentTarget).find('form[data-validate="true"]').bt_validate();  //bind validate

            $('button[type="submit"').click(function() {
                $(e.currentTarget).find("form").trigger("validate.ajax.submit");
                $.bt_validate.result[$.bt_validate.form_id];
            });
        })
    }
  }
})
